/**
 * yield()的用法
 * Created by Sean on 2017/5/9.
 */
class Thread7 extends Thread {

    @Override
    public void run() {
        for (int i = 1; i <= 50; i++) {
            System.out.println("" + this.getName() + "-----" + i);
            // 当i为30时，该线程就会把CPU时间让掉，让其他或者自己的线程执行（也就是谁先抢到谁执行）
            if (i == 30) {
                this.yield();
            }
        }
    }
}

public class Main7 {
    public static void main(String[] args) {
        Thread7 thread1 = new Thread7();
        Thread7 thread2 = new Thread7();
        thread1.setName("A线程");
        thread2.setName("B线程");
        thread1.start();
        thread2.start();
    }
}
